import axios from 'axios'
import qs from "qs";
import { Promise } from 'core-js'

var instance = axios.create({
    baseURL: 'http://localhost:2345',
    timeout: 5000,
});

instance.interceptors.request.use(config => {
        if (config.method == 'post') {
            config.data = qs.stringify({...config.data })
        } else {
            config.params = {...config.params }
        }
        config.headers['Content-Type'] = 'application/x-www-form-urlencoded';
        return config
    },
    err => {
        return Promise.reject(err)
    })

instance.interceptors.response.use(
    response => {
        return response
    },
    error => {
        return Promise.reject(error)
    }
)

export default instance